import axios from "axios";

import NProgress from "nprogress";
import "nprogress/nprogress.css";

export function request(config) {
  // 创建axios实例
  const instance = axios.create({
    baseURL: "http://127.0.0.1:3001/",
    // baseURL: "http://39.105.40.148:3001/",
    timeout: 3000,
  });

  // axios拦截器
  instance.interceptors.request.use(
    (config) => {
      // 展示进度条
      NProgress.start();
      return config;
    },
    (err) => {}
  );

  instance.interceptors.response.use(
    (res) => {
      NProgress.done();
      // 隐藏进度条
      return res.data;
    },
    (err) => {}
  );

  return instance(config);
}
